package org.tamal.jsf;

import java.util.Locale;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.tamal.Util;

/**
 * This listener sets the user locale.
 * @author Tamal Kanti Nath
 */
@FacesConverter(forClass = Locale.class)
public final class LocaleConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component,
            String value) {
        return Util.convertLocale(value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component,
            Object value) {
        return value.toString();
    }

}
